package luongvd.logoutaccount;

import java.util.ArrayList;
import java.util.List;

import luongvd.logoutaccount.common.ServerConnectionUtils;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.Handler;

public class ServerDelegate {
	public static final String LINK_SERVER = "http://m.s2vnn.com/ajax/mobile/app/";
	public static final String LINK_GET_URL = LINK_SERVER + "getLink/";
	public static final String LINK_SET_DONE = LINK_SERVER + "setDone/";
	public static final String LINK_SET_DONE_DOWNLOAD = LINK_SERVER
			+ "setDoneDownload/";
	public static final String LINK_CHECK_LOGIN = LINK_SERVER
			+ "checkHasLogin/";
	public static String strLocation = "DMM21";

	public static Thread connectServer(final Handler handler, final String url) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("locale", strLocation));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				ServerConnectionUtils.getFromURL(url, params, handler, null);
			}
		};
		return ServerConnectionUtils.performOnBackgroundThread(runnable);
	}

	public static Thread connectServerToCheckInstall(final Handler handler,
			final String url, final String account, final String link) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("locale", strLocation));
		params.add(new BasicNameValuePair("account", account));
		params.add(new BasicNameValuePair("link", link));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				ServerConnectionUtils.getFromURL(url, params, handler, null);
			}
		};
		return ServerConnectionUtils.performOnBackgroundThread(runnable);
	}

	public static Thread connectServerToCheckLogin(final Handler handler,
			final String url, final String login) {
		final List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("locale", strLocation));
		params.add(new BasicNameValuePair("status", login));
		final Runnable runnable = new Runnable() {
			@Override
			public void run() {
				ServerConnectionUtils.getFromURL(url, params, handler, null);
			}
		};
		return ServerConnectionUtils.performOnBackgroundThread(runnable);
	}

}
